<template>
  <div style="font-size: 14px;">
    <header id="home-header">
      <div id="xdcat">
        <img src="../assets/img/logo.png" style="animation-play-state: running; animation-iteration-count: 8;">
      </div>
      <a @click="toSearch" id="home-search">
        <van-icon name="search" size="20" style="margin: 3px 10px 0 10px;"/>
        <span>搜索商品名称</span>
      </a>
      <a v-if="!userInfo.id" @click="toLogin" class="home-login">
        <img src="../assets/img/default_avatar.png">
      </a>
      <a v-if="userInfo.id" class="home-login" @click="toUser">
        <img :src="userInfo.avatar">
      </a>
    </header>
  </div>
</template>

<script>

  import { mapGetters } from 'vuex';
  import { Icon } from 'vant';

  export default {
    components: {
      [Icon.name]: Icon
    },

    data() {
      return {
      };
    },
    computed: {
      ...mapGetters([
        'userInfo'
      ])
    },
    mounted() {
    },
    methods: {
      toSearch(){//跳转搜索
        this.$router.push({'path': '/search'});
      },
      toLogin(){//跳转登录
        this.$router.push({'path': '/login'});
      },
      toUser(){//跳转我的
        this.$router.push({'path': '/user'});
      }
    }
  };
</script>

<style scoped>
  #home-header {
    width: 100%;
    height: 3rem;
    background: #e9e9e9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: fixed;
    z-index: 3;
    left: 0;
    top: 0;
  }
  #xdcat {
    position: relative;
    margin: 0 1rem;
  }
  #xdcat img:first-child {
    position: relative;
    z-index: 5;
    -webkit-animation: xdcat 3s ease-in-out 2s 6 alternate both;
    animation: xdcat 3s ease-in-out 2s 6 alternate both;
  }

  .home-login img, #xdcat img {
    display: block;
    width: 2rem;
    height: 2rem;
  }
  #home-search {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    background: #fff;
    height: 2rem;
    width: 100%;
    border: 0.05rem solid #bfbfbf;
    border-radius: 2rem;
    color: #bfbfbf;
  }
  #home-search img {
    width: 1rem;
    height: 1rem;
    padding: 0 0.5rem 0 1rem;
  }
  .home-login {
    margin: 0 1rem;
  }
  a {
    text-decoration: none;
    color: #000;
  }
  .home-login img {
    border-radius: 50%;
  }
</style>
